<?php

use Faker\Factory as Faker;
use App\Models\Freight;
use App\Repositories\FreightRepository;

trait MakeFreightTrait
{
    /**
     * Create fake instance of Freight and save it in database
     *
     * @param array $freightFields
     * @return Freight
     */
    public function makeFreight($freightFields = [])
    {
        /** @var FreightRepository $freightRepo */
        $freightRepo = App::make(FreightRepository::class);
        $theme = $this->fakeFreightData($freightFields);
        return $freightRepo->create($theme);
    }

    /**
     * Get fake instance of Freight
     *
     * @param array $freightFields
     * @return Freight
     */
    public function fakeFreight($freightFields = [])
    {
        return new Freight($this->fakeFreightData($freightFields));
    }

    /**
     * Get fake data of Freight
     *
     * @param array $postFields
     * @return array
     */
    public function fakeFreightData($freightFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'shop_id' => $fake->randomDigitNotNull,
            'name' => $fake->word,
            'type' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $freightFields);
    }
}
